﻿using System.Net.Sockets;
using System.Net;
using System.Text;

Socket udpServer = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp);
IPAddress ipAddress = new IPAddress(new byte[] { 192, 168, 10, 100 });
IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, 11111);
udpServer.Bind(ipEndPoint);
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 0);
EndPoint EP = (EndPoint)ipep;
byte[] data = new byte[1024];
int length = udpServer.ReceiveFrom(data, ref EP);
Console.WriteLine("接收到的数据：" + Encoding.UTF8.GetString(data, 0, length));
udpServer.Close();